package kr.hkit.powerjava.chapter24.submit3;

import java.util.Comparator;
import java.util.Scanner;

public class StudentService_Service extends ServiceItem_Service<Student_Vo> {

	
	public StudentService_Service(Interface_Dao<Student_Vo> dao, Scanner sc) {
		super(dao, sc);
	}
	
	@Override
	public Student_Vo inputItemInfo(boolean gubun) { //gubun이 필요한가?? false면?
		System.out.println("학번 성명");
		Student_Vo std = new Student_Vo(sc.nextInt(), sc.next().trim()); 
		if (gubun) {
			System.out.println("국어 영어 수학");
			std.setKor(sc.nextInt());
			std.setEng(sc.nextInt());
			std.setMath(sc.nextInt());
		}
		return std;
	}

	@Override
	public void prnSubMenu() { //정렬용 
		
		int res = 0;
		System.out.println("1.이름순 정렬 2.성적순 정렬 3.번호순 정렬");
		res = sc.nextInt();
		
		switch(res) {
			case 1:
				dao.prnItem(new Comparator<Student_Vo>() {
					@Override
					public int compare(Student_Vo o1, Student_Vo o2) {
						return o1.getStdName().hashCode() - o2.getStdName().hashCode();
					}
				});
				break;
				
			case 2:
				dao.prnItem(new Comparator<Student_Vo>() {
					@Override
					public int compare(Student_Vo o1, Student_Vo o2) {
						return o1.getTotal() - o2.getTotal();
					}
				});
				break;
				
			default:
				dao.prnItem(null);
				break;
			
		}
	}

}
